<template>

 <sweet-modal ref="dialogInfo" class="dialog"  :sweetModalMaxWidth="pageWidth">
     <h3>{{title}}</h3>
      <div :style="{maxHeight:maxHeight+'px'}" style="overflow:auto;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">电话姓名</label>
                <div class="layui-input-inline">
                    <el-input v-model="ImgData.CALNAME" style="width:200px;" :readonly="isdisabled"></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">电话号码</label>
                <div class="layui-input-inline">
                    <el-input v-model="ImgData.CALNUM" style="width:200px;" :readonly="isdisabled"></el-input>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">电话地址</label>
                <div class="layui-input-inline">
                    <el-input v-model="ImgData.CALADDRESS" style="width:200px;" :readonly="isdisabled"></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">电话来源</label>
                <div class="layui-input-inline">
                    <el-input v-model="ImgData.CALDPTID" style="width:200px;" :readonly="!isdisabled"></el-input>
                </div>
        </div>
        </div>
      </div>
    <div class="layui-form-item btnCenter sweet-btn">
        <el-button  @click="submit">保存</el-button>
        <el-button  @click="closeDialog">取消</el-button>
    </div>
 </sweet-modal>

</template>

<style  rel="stylesheet/scss" lang="scss">
    .textareas .el-textarea__inner{
        height: 100px!important;
    }
</style>
<script>
const INFO="详情"
const ADD = "新增"
const MODIFY = "修改"
const sends = "发送"
import apiBase from "@/api/apiBase.js";
import sweetModal from "@/components/sweetModal";
import {  formatDate,timeStringToDate,dateStringToDate } from "@/utils/date.js";
  export default {
    data(){
        return{
            DeptName:null,
            DeptId:null,
            ImgData: {
                CALDPTID:null,
                CALNUM: null,
                CALNAME: null,
                CALADDRESS: null,
            },
            call_from: [],//电话来源

            CALID: null,
            isdisabled: null,
            
            pageWidth: 700,
            maxHeight: 500,
            title:null,
            order:null,
        }
    },
      methods:{
        open(order, id) {
            this.order = order;
            this.CALID = id;
            this.dataRepeat();
            this.getcall_from();//获取电话来源
            switch (this.order) {
                case INFO:
                    this.dataInfo(id);
                    this.isdisabled = true;
                    this.title = "电话配置详情";
                     this.$refs.dialogInfo.open();
                    break;
                case ADD:
                    this.isdisabled = false;
                    this.$refs.dialogInfo.open();
                    this.title = "电话配置新增";
                    let DeptName = localStorage.getItem('DeptName');
                    this.ImgData.CALDPTID = DeptName;
                    break;
                case MODIFY:
                    
                    this.isdisabled = false;
                    this.$refs.dialogInfo.open();
                    this.title = "电话配置修改";
                    this.dataInfo(id);
                    break;
            default:
            }
        },
      
        //提交
        submit(checkout = false) {
            switch (this.order) {
                case ADD:
                    this.dataadd();
                    break;
                case MODIFY:
                    this.datamodify();
                    break;
                default:
            }
        },
      
        //新增
        dataadd(){
            let data = JSON.parse(JSON.stringify(this.ImgData));
            data.CALDPTID = this.DeptId
            apiBase.DoService(
                data,
                apiBase.getApiAdress().ShortMsg.CreateCal,
                res => {
                    this.$message({
                        type: "success",
                        message: "新增成功!"
                    });
                    this.$refs.dialogInfo.close();
                    this.refreshData();
                    
                }
            );
        },
        //获取电话来源
        getcall_from(){
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().ShortMsg.GetCalForm ,
                res => {
                    this.call_from = res.data.content;
                }
            );
        },
        //修改
        datamodify(){
            let data = JSON.parse(JSON.stringify(this.ImgData));
            data.CALID = this.CALID;
         
            apiBase.DoService(
                data,
                apiBase.getApiAdress().ShortMsg.ModifyCal ,
                res => {
                    this.$message({
                        type: "success",
                        message: "修改成功!"
                    });
                    this.$refs.dialogInfo.close();
                    this.refreshData();
                }
            );
        },
        closeDialog() {
            this.$refs.dialogInfo.close();
        },
        refreshData(){
            this.$emit('refreshData');
        },
        //登记详情
        dataInfo(id) {
            let data = {
                CALID: id
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().ShortMsg.DetailCal,
                res => {
                    this.ImgData.CALADDRESS = res.data.content.CALADDRESS;
                    this.ImgData.CALNAME = res.data.content.CALNAME;
                    this.ImgData.CALNUM = res.data.content.CALNUM;
                    this.ImgData.CALDPTID = res.data.content.CALDPTID;
            })
        }, 
        //数据重置
        dataRepeat(){
            this.ImgData =  {
               CALDPTID: null,
                CALNUM: null,
                CALNAME: null,
                CALADDRESS: null,
            };
        },
    },
    components: {
        sweetModal
    },
    mounted() {
        
    },
    // 传给后台部门id
    created() {
        let DeptId = localStorage.getItem('DeptId');
        let DeptName = localStorage.getItem('DeptName');
        this.DeptName = DeptName;
        this.DeptId = DeptId;
    },
  };
</script>

